<?php
  require_once('tpl/header.php');
?>
<?php 
require_once("loginCheckadmin.php");
require_once("../system/dbConn.php");
connect();


 $old=$_POST["old"];
     $new1=$_POST["new1"];
      $new2=$_POST["new2"];
 //取数据库中的原密码
    $adminname=$_SESSION["adminname"];
    $sql="select password from admins where adminname='$adminname' ";
   //var_dump($row);

      $result=mysqli_query($link,$sql);
//整型
    $row=mysqli_fetch_assoc($result);

if(strcmp(md5($old), $row["password"])!=0){
      
      header("location:changePassword.php?msg1=原密码输入不正确！");
}
elseif(strcmp($new1, $new2)!=0){
      
      header("location:changePassword.php?msg2=新密码确认有误！");


}else{
$sql1="update admins set password=md5('$new1') where adminname='$adminname'";
     $result1=mysqli_query($link,$sql1);

    if ($result1==1) {
      echo "密码修改成功,2秒后跳回欢迎页";
      header("refresh:2;url='welcome.php'");
    }
    else{
      echo "修改失败";
    }
}

   
 ?>

<?php
  require_once('tpl/footer.php');
?>